#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
    vector<int> path;
    vector<vector<int>> res;
public:
    vector<vector<int>> findPath(TreeNode* root, int sum) {
        dfs(root, sum);
        return res;
    }

    void dfs(TreeNode* root, int sum) {
        if (!root) return;
        sum = sum - root->val;

        path.push_back(root->val);
        if (!root->left && !root->right && !sum) res.push_back(path);
        dfs(root->left, sum);
        dfs(root->right, sum);
        path.pop_back();
    }
};
